// @ts-ignore
import CryptoJS from 'crypto-js'
const key = CryptoJS.enc.Utf8.parse('1234567890abcdef')
const iv = CryptoJS.enc.Utf8.parse('fedcba0987654321')

export const encrypt = (text: string) => {
  const encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(text), key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  return encrypted.toString()
}

// 解密函数
export const decrypt = (text: string) => {
  const decrypted = CryptoJS.AES.decrypt(text, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  return decrypted.toString(CryptoJS.enc.Utf8)
}
